*Preliminary Data Analysis
*Adhikari, King, Murdie ISA 2023

clear 
cd "C:\Users\murdie\Dropbox\2022 Adhikari King and Murdie\Democratic Backsliding Paper\Data Analysis"
use WorkingDataset.dta, replace 

*Let's just look at trends in democracy and human rights

*Human Rights

*yearly average - human rights Fariss 
bysort year: egen yearlytheta_mean = mean(theta_mean)
label variable yearlytheta_mean "Yearly World Mean - Fariss Human Rights Score"

line yearlytheta_mean year if ccode==2
graph save "Graph" "Yearly Fariss Mean.gph", replace 
graph export "Yearly Fariss Mean.tif", replace 

*VDEM - v2x_clphy
bysort year: egen yearlyv2x_clphy = mean(v2x_clphy)
label variable yearlyv2x_clphy "Yearly World Mean - VDEM Physical Violence Index"

line yearlyv2x_clphy year if ccode==2
graph save "Graph" "Yearly VDem Physical Violence.gph", replace
graph export "Yearly VDem Physical Violence.tif", replace 

*PTS - Amnesty  ***NOTE: this scale goes the opposite way - larger numbers are worse HR
bysort year: egen yearlyPTS_A = mean(PTS_A)
label variable yearlyPTS_A "Yearly World Mean - PTS - Amnesty"

line yearlyPTS_A year if ccode==2 & year>1980
graph save "Graph" "Yearly PTS Amnesty.gph", replace
graph export "Yearly PTS Amnesty.tif", replace

*PTS - State ***NOTE: this scale goes the opposite way - larger numbers are worse HR
bysort year: egen yearlyPTS_S = mean(PTS_S)
label variable yearlyPTS_S "Yearly World Mean - PTS - State"

line yearlyPTS_S year if ccode==2 & year>1980
graph save "Graph" "Yearly PTS State.gph", replace
graph export "Yearly PTS State.tif", replace

*Democracy - Polity score -10 to 10
bysort year: egen yearlypolity2 = mean(polity2)
label variable yearlypolity2 "Yearly World Mean - Polity"

line yearlypolity2 year if ccode==2
graph save "Graph" "Yearly Polity.gph", replace
graph export "Yearly Polity.tif", replace


*VDEM's democracy scales 
*Electoral democracy index (D) (v2x_polyarchy)
*Liberal democracy index (D) (v2x_libdem)
*Participatory democracy index (D) (v2x_partipdem)
*Deliberative democracy index (D) (v2x_delibdem)
*Egalitarian democracy index (D) (v2x_egaldem)


*What is our argument - human rights gains in full democracies (Davenport and Armstrong) but loses the most when democracies "backslide"

*democratic backsliding has a unique effect on human rights, different than changes in the positive direction (how would we best measure that empirically? Hmmm)


foreach var of varlist v2x_polyarchy v2x_libdem v2x_partipdem v2x_delibdem v2x_egaldem {

bysort year: egen yearly`var' = mean(`var')
label variable yearly`var' "Yearly `var'"

line yearly`var' year if ccode==2
graph save "Graph" "Yearly `var'.gph", replace
graph export "Yearly `var'.tif", replace

}


****Let's just try a general model
tsset ccode year 
reg theta_mean l.theta_mean polity2 lnwdi_pop lnwdi_gdpcapcon2015 intllocation civillocation, robust

*Davenport and Armstrong
gen allpositivepolity2 = polity2 + 11
reg theta_mean l.theta_mean i.allpositivepolity2 lnwdi_pop lnwdi_gdpcapcon2015 intllocation civillocation, robust


*VDem indicators
foreach var of varlist v2x_polyarchy v2x_libdem v2x_partipdem v2x_delibdem v2x_egaldem {

reg theta_mean l.theta_mean `var' lnwdi_pop lnwdi_gdpcapcon2015 intllocation civillocation, robust
}

*Ok, so easy to conclude that democracy is important for human rights, good

*Now, how do we think of democratic transitions and backsliding?

*of course, Polity's regtrans 

*Maybe start with focusing on some change in a given period of time 

*Pieters et al 2016 - 10 years above 0 on polity2, must have 10 years as autocracy before transition

*Bruckner and Ciccone 2011 - transition=1 in t if improvements from t to t+1 lead to a country being upgraded to a democracy (same thing for transition to full democracy (7 and above))


*Bruckner et al 2012*We also construct a democratic transition indicator that takes the value of 1 in year t if the country is a democracy in year t but was an autocracy in year t — 1, and an auto cratic reversal indicator that takes the value of 1 in year t if the country is an autocracy in year t but was a democracy in year t —1

*Jee et al 2022 *We need to consider our indicators, magnitide, and time horizon *consider four common measures of backsliding: (1) any negative change on the Polity scale,11 (2) any positive change on the Freedom in the World Index,12 (3) negative changes by at least 0.05 on V-Dem's polyarchy index,13 or (4) negative changes by at least 0.5 on BTI's democracy score.14...Some scholars consider any negative change. Others use a larger threshold, such as decreases in a country's Polity score of at least 2 or 3 points.15...Some scholars consider any negative change. Others use a larger threshold,such as decreases in a country's Polity score of at least 2 or 3 points.15


*Let's try some of these measures of negative change

*Any negative change on polity2
tsset ccode year
gen AnyNegativePolity = .
replace AnyNegativePolity = 0 if polity2 >= l.polity2 & polity2!=. & l.polity2!=.
replace AnyNegativePolity = 1 if polity2 < l.polity2 & polity2!=. & l.polity2!=.

reg theta_mean l.theta_mean AnyNegativePolity polity2 lnwdi_pop lnwdi_gdpcapcon2015 intllocation civillocation, robust
*good, negative and stat sig

*negative changes by at least 0.05 on V-Dem's polyarchy index v2x_polyarchy

tsset ccode year
gen PolyarchyDrop = .
replace PolyarchyDrop = 0 if ((v2x_polyarchy -l.v2x_polyarchy)>=-0.05) & v2x_polyarchy!=. & v2x_polyarchy!=.
replace PolyarchyDrop = 1 if ((v2x_polyarchy -l.v2x_polyarchy)<-0.05) & v2x_polyarchy!=. & v2x_polyarchy!=.

reg theta_mean l.theta_mean v2x_polyarchy PolyarchyDrop  lnwdi_pop lnwdi_gdpcapcon2015 intllocation civillocation, robust


*And, with lagged variables (probably use this model)

label variable AnyNegativePolity "Democratic Backsliding - Any Drop in Polity2"
label variable PolyarchyDrop "Democratic Backsliding - Drop in  V-Dem's Polyarchy Index Greater than 0.05"

reg theta_mean l.theta_mean AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table1 ,  replace word se label


reg theta_mean l.theta_mean PolyarchyDrop  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table1 ,  append word se label



**drops of more than 2 points on polity 

tsset ccode year
gen Dropoftwopolity = .
replace Dropoftwopolity= 0 if ((polity2  -l.polity2 )>=-2) & polity2!=. & polity2 !=.
replace Dropoftwopolity = 1 if ((polity2 -l.polity2 )<-2) & polity2 !=. & polity2 !=.

label variable Dropoftwopolity "Democratic Backsliding - Drop of 2 or More Polity2"

reg theta_mean l.theta_mean Dropoftwopolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table1 ,  append word se label


***drops of more than 3 on polity 


tsset ccode year
gen Dropofthreepolity = .
replace Dropofthreepolity= 0 if ((polity2  -l.polity2 )>=-3) & polity2!=. & polity2 !=.
replace Dropofthreepolity = 1 if ((polity2 -l.polity2 )<-3) & polity2 !=. & polity2 !=.

label variable Dropofthreepolity "Democratic Backsliding - Drop of 3 or More Polity2"

reg theta_mean l.theta_mean Dropofthreepolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table1 ,  append word se label



*drops of more than 1 SD greater than the mean difference in VDEM Polyarchy


sum D.v2x_polyarchy
gen Dv2x_polyarchy= D.v2x_polyarchy
sum Dv2x_polyarchy

*drop is mean - 2 SD 
gen LargerthanSEdropv2x_polyarchy= 0 if Dv2x_polyarchy!=.
replace LargerthanSEdropv2x_polyarchy = 1 if Dv2x_polyarchy<=-.0795815 & Dv2x_polyarchy!=.

label variable LargerthanSEdropv2x_polyarchy "Democratic Backsliding - Drop of V-Dem's Polyarchy Index Greater than Mean - 2 SD"

reg theta_mean l.theta_mean LargerthanSEdropv2x_polyarchy l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table1 ,  append word se label



*Ok, good start - let's make a table 


*Let's try a model without lagged dvar 

reg theta_mean  AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table2 ,  replace word se label
	coefplot, drop(_cons) xline(0) 


reg theta_mean  PolyarchyDrop  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table2 ,  append word se label
	coefplot, drop(_cons) xline(0) 

reg theta_mean  Dropoftwopolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table2 ,  append word se label
	coefplot, drop(_cons) xline(0) 


reg theta_mean Dropofthreepolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table2 ,  append word se label
	coefplot, drop(_cons) xline(0) 


reg theta_mean LargerthanSEdropv2x_polyarchy l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table2 ,  append word se label
	coefplot, drop(_cons) xline(0) 

	coefplot, drop(_cons) xline(0) 


**2/25/2023

*Additional tests for paper

*CIRIGHTS instead - all works
reg physint l.physint AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table3 ,  replace word se label

reg physint l.physint PolyarchyDrop  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table3 ,  append word se label

reg physint l.physint Dropoftwopolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table3 ,  append word se label

reg physint l.physint Dropofthreepolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table3 ,  append word se label

reg physint l.physint LargerthanSEdropv2x_polyarchy l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, 
*outreg2 using Table3 ,  append word se label

*PTS - all works as well
reg PTS_A l.PTS_A AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table4 ,  replace word se label

reg PTS_A l.PTS_A PolyarchyDrop  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table4 ,  append word se label

reg PTS_A l.PTS_A Dropoftwopolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table4 ,  append word se label

reg PTS_A l.PTS_A Dropofthreepolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table4 ,  append word se label

reg PTS_A l.PTS_A LargerthanSEdropv2x_polyarchy l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, 
*outreg2 using Table4 ,  append word se label

*back to original DVAR, include politysquared or polyarchysquared - still works
reg theta_mean l.theta_mean AnyNegativePolity c.l.polity2##c.l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table5 ,  replace word se label


reg theta_mean l.theta_mean PolyarchyDrop  c.l.v2x_polyarchy##c.c.l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table5 ,  append word se label


reg theta_mean l.theta_mean Dropoftwopolity c.l.polity2##c.l.polity2  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table5 ,  append word se label

reg theta_mean l.theta_mean Dropofthreepolity c.l.polity2##c.l.polity2  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table5 ,  append word se label


reg theta_mean l.theta_mean LargerthanSEdropv2x_polyarchy c.l.v2x_polyarchy##c.c.l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, 
*outreg2 using Table5 ,  append word se label


*interactions
*with NGO aid  -  I don't think this works
reg theta_mean l.theta_mean AnyNegativePolity##c.l.lnAidAllNGOs l.lnAllAid  l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table6 ,  replace word se label


reg theta_mean l.theta_mean PolyarchyDrop##c.l.lnAidAllNGOs l.lnAllAid  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table6 ,  append word se label


reg theta_mean l.theta_mean Dropoftwopolity##c.l.lnAidAllNGOs l.lnAllAid l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table6 ,  append word se label

reg theta_mean l.theta_mean Dropofthreepolity##c.l.lnAidAllNGOs l.lnAllAid l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table6 ,  append word se label


reg theta_mean l.theta_mean LargerthanSEdropv2x_polyarchy##c.l.lnAidAllNGOs l.lnAllAid l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, 
*outreg2 using Table6 ,  append word se label


**HRaid * doesn't work either 
reg theta_mean l.theta_mean AnyNegativePolity##c.l.lnAidHumanRights l.lnAllAid  l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table7 ,  replace word se label


reg theta_mean l.theta_mean PolyarchyDrop##c.l.lnAidHumanRights l.lnAllAid  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table7 ,  append word se label


reg theta_mean l.theta_mean Dropoftwopolity##c.l.lnAidHumanRights l.lnAllAid l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table7 ,  append word se label

reg theta_mean l.theta_mean Dropofthreepolity##c.l.lnAidHumanRights l.lnAllAid l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table7 ,  append word se label


reg theta_mean l.theta_mean LargerthanSEdropv2x_polyarchy##c.l.lnAidHumanRights l.lnAllAid l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, 
*outreg2 using Table7 ,  append word se label


*latent independent judiciary - works on first one but nothing else
reg theta_mean l.theta_mean AnyNegativePolity##c.l.lji  l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table8 ,  replace word se label


reg theta_mean l.theta_mean PolyarchyDrop##c.l.lji  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table8 ,  append word se label


reg theta_mean l.theta_mean Dropoftwopolity##c.l.lji l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table8 ,  append word se label

reg theta_mean l.theta_mean Dropofthreepolity##c.l.lji l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table8 ,  append word se label


reg theta_mean l.theta_mean LargerthanSEdropv2x_polyarchy##c.l.lji l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, 
*outreg2 using Table8 ,  append word se label

*state quality - icrg_qog
reg theta_mean l.theta_mean AnyNegativePolity##c.l.icrg_qog  l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table9 ,  replace word se label


reg theta_mean l.theta_mean PolyarchyDrop##c.l.icrg_qog  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table9 ,  append word se label


reg theta_mean l.theta_mean Dropoftwopolity##c.l.icrg_qog l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table9 ,  append word se label

reg theta_mean l.theta_mean Dropofthreepolity##c.l.icrg_qog l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
*outreg2 using Table9 ,  append word se label


reg theta_mean l.theta_mean LargerthanSEdropv2x_polyarchy##c.l.icrg_qog l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, 
*outreg2 using Table9 ,  append word se label


*with regional fixed effects - still works
reg theta_mean l.theta_mean AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table10 ,  replace word se label

reg theta_mean l.theta_mean PolyarchyDrop  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table10 ,  append word se label

reg theta_mean l.theta_mean Dropoftwopolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table10 ,  append word se label

reg theta_mean l.theta_mean Dropofthreepolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table10 ,  append word se label

reg theta_mean l.theta_mean LargerthanSEdropv2x_polyarchy l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, 
*outreg2 using Table10 ,  append word se label


*One year in the future -still works 
reg F.theta_mean l.theta_mean AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table11 ,  replace word se label

reg F.theta_mean l.theta_mean PolyarchyDrop  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table11 ,  append word se label

reg F.theta_mean l.theta_mean Dropoftwopolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table11 ,  append word se label

reg F.theta_mean l.theta_mean Dropofthreepolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table11 ,  append word se label

reg F.theta_mean l.theta_mean LargerthanSEdropv2x_polyarchy l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, 
*outreg2 using Table11 ,  append word se label


*two years - still works
reg F2.theta_mean l.theta_mean AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table12 ,  replace word se label

reg F2.theta_mean l.theta_mean PolyarchyDrop  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table12 ,  append word se label

reg F2.theta_mean l.theta_mean Dropoftwopolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table12 ,  append word se label

reg F2.theta_mean l.theta_mean Dropofthreepolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table12 ,  append word se label

reg F2.theta_mean l.theta_mean LargerthanSEdropv2x_polyarchy l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, 
*outreg2 using Table12 ,  append word se label


*three years - still works 
reg F3.theta_mean l.theta_mean AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table13 ,  replace word se label

reg F3.theta_mean l.theta_mean PolyarchyDrop  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table13 ,  append word se label

reg F3.theta_mean l.theta_mean Dropoftwopolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table13 ,  append word se label

reg F3.theta_mean l.theta_mean Dropofthreepolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table13 ,  append word se label

reg F3.theta_mean l.theta_mean LargerthanSEdropv2x_polyarchy l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, 
*outreg2 using Table13 ,  append word se label


*four years - still works 
reg F4.theta_mean l.theta_mean AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table14 ,  replace word se label

reg F4.theta_mean l.theta_mean PolyarchyDrop  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table14 ,  append word se label

reg F4.theta_mean l.theta_mean Dropoftwopolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table14 ,  append word se label

reg F4.theta_mean l.theta_mean Dropofthreepolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table14 ,  append word se label

reg F4.theta_mean l.theta_mean LargerthanSEdropv2x_polyarchy l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, 
*outreg2 using Table14 ,  append word se label

*five years - many still work 
reg F5.theta_mean l.theta_mean AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table15 ,  replace word se label

reg F5.theta_mean l.theta_mean PolyarchyDrop  l.v2x_polyarchy  l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table15 ,  append word se label

reg F5.theta_mean l.theta_mean Dropoftwopolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table15 ,  append word se label

reg F5.theta_mean l.theta_mean Dropofthreepolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, robust
*outreg2 using Table15 ,  append word se label

reg F5.theta_mean l.theta_mean LargerthanSEdropv2x_polyarchy l.v2x_polyarchy l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation i.ht_region, 
*outreg2 using Table15 ,  append word se label
 
*Summary stats for baseline model 

ssc install sum2docx
*sum2docx theta_mean  AnyNegativePolity PolyarchyDrop Dropoftwopolity Dropofthreepolity LargerthanSEdropv2x_polyarchy LargerthanSEdropv2x_polyarchy v2x_polyarchy lnwdi_pop lnwdi_gdpcapcon2015 intllocation civillocation using summary.docx, replace stats(N mean median sd min max)

gen ltheta_mean = l.theta_mean
reg theta_mean ltheta_mean i.AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust
	coefplot, drop(_cons ltheta_mean) xline(0) 
	margins  i.AnyNegativePolity,   vsquish at((means) _continuous l.intllocation=0 l.civillocation=0)
	
	
	sum l.lnwdi_gdpcapcon2015 if e(sample)
		margins ,   vsquish at((means) _continuous l.intllocation=0 l.civillocation=0 l.lnwdi_gdpcapcon2015=4.98)
		margins ,   vsquish at((means) _continuous l.intllocation=0 l.civillocation=0 l.lnwdi_gdpcapcon2015=11.64)
	
	* 4.976951   11.64438
	 

	reg physint l.physint i.AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust 
	 margins  i.AnyNegativePolity,   vsquish at((means) _continuous l.intllocation=0 l.civillocation=0)
	 	margins ,   vsquish at((means) _continuous l.intllocation=0 l.civillocation=0 l.lnwdi_gdpcapcon2015=4.98)
		margins ,   vsquish at((means) _continuous l.intllocation=0 l.civillocation=0 l.lnwdi_gdpcapcon2015=11.64)
		
		
		
		 gen lcivil = l.civil
	reg physint l.physint i.AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation i.lcivil, robust 
		 margins  i.lcivil,   vsquish at((means) _continuous l.intllocation=0 AnyNegativePolity=0)
		
		
		
		reg PTS_A  l.PTS_A i.AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust 
	 margins  i.AnyNegativePolity,   vsquish at((means) _continuous l.intllocation=0 l.civillocation=0)

****April 12, 2023 - playing around with over time effects


reg theta_mean l.theta_mean AnyNegativePolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust

gen lpolity2 = l.polity2
gen llnwdi_pop = l.lnwdi_pop
gen llnwdi_gdpcapcon2015 = l.lnwdi_gdpcapcon2015
gen lintllocation = l.intllocation
gen lcivillocation = l.civillocation
gen lv2x_polyarchy = l.v2x_polyarchy

save LDEdataset.dta, replace 

reg theta_mean ltheta_mean AnyNegativePolity lpolity2 llnwdi_pop llnwdi_gdpcapcon2015 lintllocation lcivillocation

sum ltheta_mean if e(sample)
*.2208221

estsimp reg theta_mean ltheta_mean AnyNegativePolity lpolity2 llnwdi_pop llnwdi_gdpcapcon2015 lintllocation lcivillocation, robust sims(1000)

dynsim, ldv(ltheta_mean) /*
*/	scen1(ltheta_mean .2208221 lpolity2 mean llnwdi_pop mean llnwdi_gdpcapcon2015 mean lintllocation 0 lcivillocation 0  AnyNegativePolity 0) /*
*/	scen2(ltheta_mean .2208221 lpolity2 mean llnwdi_pop mean llnwdi_gdpcapcon2015 mean lintllocation 0 lcivillocation 0  AnyNegativePolity 1)  /*
*/	n(8) sig(95) sav(negativepolity)

preserve
	use negativepolity.dta, clear
	twoway (rcapsym lower_1 upper_1 t, msymbol(sh)) (rcapsym lower_2 upper_2 t, msymbol(x)) , ytitle("Human Rights Protection Score", size(medlarge)) /*
	*/ legend(label(1 "No Backsliding") label(2 "Democratic Backsliding - Any Drop in Polity2") pos(6) col(1)) /*
	*/ xtitle("Year", size(medlarge)) xlabel(1(2)9)

graph save "Graph" "Dynamicpolity2drop.gph", replace 
restore

use LDEdataset.dta, replace 

reg theta_mean ltheta_mean PolyarchyDrop  lv2x_polyarchy  llnwdi_pop llnwdi_gdpcapcon2015 lintllocation lcivillocation

sum ltheta_mean if e(sample)
*.279901

estsimp reg theta_mean ltheta_mean PolyarchyDrop  lv2x_polyarchy  llnwdi_pop llnwdi_gdpcapcon2015 lintllocation lcivillocation, robust sims(1000)


dynsim, ldv(ltheta_mean) /*
*/	scen1(ltheta_mean .279901 lv2x_polyarchy mean llnwdi_pop mean llnwdi_gdpcapcon2015 mean lintllocation 0 lcivillocation 0  PolyarchyDrop 0) /*
*/	scen2(ltheta_mean .279901 lv2x_polyarchy mean llnwdi_pop mean llnwdi_gdpcapcon2015 mean lintllocation 0 lcivillocation 0  PolyarchyDrop 1)  /*
*/	n(8) sig(95) sav(negativepoly)

preserve
	use negativepoly.dta, clear
	twoway (rcapsym lower_1 upper_1 t, msymbol(sh)) (rcapsym lower_2 upper_2 t, msymbol(x)) , ytitle("Human Rights Protection Score", size(medlarge)) /*
	*/ legend(label(1 "No Backsliding") label(2 "Democratic Backsliding - Drop in V-Dem's Polyarchy Index Greater than 0.05") pos(6) col(1)) /*
	*/ xtitle("Year", size(medlarge)) xlabel(1(2)9)

graph save "Graph" "Dynamicpolyarchydrop.gph", replace 
restore


use LDEdataset.dta, replace 

reg theta_mean l.theta_mean Dropoftwopolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust

sum ltheta_mean if e(sample)
*.2208221 

estsimp reg theta_mean ltheta_mean Dropoftwopolity lpolity2 llnwdi_pop llnwdi_gdpcapcon2015 lintllocation lcivillocation, robust sims(1000)


dynsim, ldv(ltheta_mean) /*
*/	scen1(ltheta_mean .2208221 lpolity2  mean llnwdi_pop mean llnwdi_gdpcapcon2015 mean lintllocation 0 lcivillocation 0  Dropoftwopolity 0) /*
*/	scen2(ltheta_mean .2208221  lpolity2  mean llnwdi_pop mean llnwdi_gdpcapcon2015 mean lintllocation 0 lcivillocation 0  Dropoftwopolity 1)  /*
*/	n(8) sig(95) sav(negative2polity)

preserve
	use negative2polity.dta, clear
	twoway (rcapsym lower_1 upper_1 t, msymbol(sh)) (rcapsym lower_2 upper_2 t, msymbol(x)) , ytitle("Human Rights Protection Score", size(medlarge)) /*
	*/ legend(label(1 "No Backsliding") label(2 "Democratic Backsliding -  Drop of 2 or More Polity2") pos(6) col(1)) /*
	*/ xtitle("Year", size(medlarge)) xlabel(1(2)9)

graph save "Graph" "Dynamic2politydrop.gph", replace 
restore

use LDEdataset.dta, replace 

reg theta_mean l.theta_mean Dropofthreepolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust

sum ltheta_mean if e(sample)
*.2208221 

estsimp reg theta_mean ltheta_mean Dropofthreepolity lpolity2 llnwdi_pop llnwdi_gdpcapcon2015 lintllocation lcivillocation, robust sims(1000)


dynsim, ldv(ltheta_mean) /*
*/	scen1(ltheta_mean .2208221 lpolity2  mean llnwdi_pop mean llnwdi_gdpcapcon2015 mean lintllocation 0 lcivillocation 0  Dropofthreepolity 0) /*
*/	scen2(ltheta_mean .2208221  lpolity2  mean llnwdi_pop mean llnwdi_gdpcapcon2015 mean lintllocation 0 lcivillocation 0  Dropofthreepolity 1)  /*
*/	n(8) sig(95) sav(negative3polity)

preserve
	use negative3polity.dta, clear
	twoway (rcapsym lower_1 upper_1 t, msymbol(sh)) (rcapsym lower_2 upper_2 t, msymbol(x)) , ytitle("Human Rights Protection Score", size(medlarge)) /*
	*/ legend(label(1 "No Backsliding") label(2 "Democratic Backsliding -  Drop of 3 or More Polity2") pos(6) col(1)) /*
	*/ xtitle("Year", size(medlarge)) xlabel(1(2)9)

graph save "Graph" "Dynamic3politydrop.gph", replace 
restore

use LDEdataset.dta, replace 

reg theta_mean ltheta_mean lv2x_polyarchy  LargerthanSEdropv2x_polyarchy  llnwdi_pop llnwdi_gdpcapcon2015 lintllocation lcivillocation

sum ltheta_mean if e(sample)
*.279901

gen Largerthan = LargerthanSEdropv2x_polyarchy 

estsimp reg theta_mean ltheta_mean Largerthan lv2x_polyarchy  llnwdi_pop llnwdi_gdpcapcon2015 lintllocation lcivillocation, robust sims(1000)


dynsim, ldv(ltheta_mean) /*
*/	scen1(ltheta_mean .279901 lv2x_polyarchy mean llnwdi_pop mean llnwdi_gdpcapcon2015 mean lintllocation 0 lcivillocation 0  Largerthan 0) /*
*/	scen2(ltheta_mean .279901 lv2x_polyarchy mean llnwdi_pop mean llnwdi_gdpcapcon2015 mean lintllocation 0 lcivillocation 0  Largerthan 1)  /*
*/	n(8) sig(95) sav(negativepoly2)

preserve
	use negativepoly2.dta, clear
	twoway (rcapsym lower_1 upper_1 t, msymbol(sh)) (rcapsym lower_2 upper_2 t, msymbol(x)) , ytitle("Human Rights Protection Score", size(medlarge)) /*
	*/ legend(label(1 "No Backsliding") label(2 "Democratic Backsliding - Drop of V-Dem's Polyarchy Index Greater than Mean - 2 SD") pos(6) col(1)) /*
	*/ xtitle("Year", size(medlarge)) xlabel(1(2)9)

graph save "Graph" "Dynamicpolyarchydrop2.gph", replace 
restore


graph combine "Dynamicpolity2drop.gph" "Dynamicpolyarchydrop.gph" "Dynamic2politydrop.gph" "Dynamic3politydrop.gph" "Dynamicpolyarchydrop2.gph"

**Let's look at some cases:


use LDEdataset.dta, replace 

reg theta_mean l.theta_mean Dropoftwopolity l.polity2 l.lnwdi_pop l.lnwdi_gdpcapcon2015 l.intllocation l.civillocation, robust

list country year if Dropoftwopolity==1 & e(sample)

twoway line theta_mean polity2 year if country=="Zambia"
twoway line theta_mean polity2 year if country=="Nepal"







